package com.sh.caryr.erp.controller.basis;

import com.sh.caryr.erp.entity.basis.SystemLog;
import com.sh.caryr.erp.exception.ResultCode;
import com.sh.caryr.erp.exception.RestServiceException;
import com.sh.caryr.erp.service.ISystemLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/systemLog")
public class SystemLogController{
	@Autowired
	private ISystemLogService systemLogService;

	@RequestMapping(method = RequestMethod.GET)
	public List<SystemLog> findSystemLogs() {
		return systemLogService.selectList(null);
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public SystemLog findSystemLogById(@PathVariable long id){
		SystemLog systemLog = systemLogService.selectById(id);

		if (systemLog == null){
			throw new RestServiceException(HttpStatus.NOT_FOUND, ResultCode.ENTITY_NOT_FOUND);
		}

		return  systemLog;
	}

	@RequestMapping(method=RequestMethod.POST)
	public Object insertSystemLog(@RequestBody SystemLog systemLog) {
		return systemLogService.insert(systemLog) ? ("添加成功") : ("添加失败");
	}

	@RequestMapping(value = "/{id}",method=RequestMethod.PUT)
	public Object updateSystemLog(@PathVariable long id, @RequestBody SystemLog systemLog) {
		systemLog.setId(id);
		return systemLogService.updateById(systemLog) ? ("修改成功") : ("修改失败");
	}
	
	@RequestMapping(value = "/{id}",method=RequestMethod.DELETE)
	public Object deleteSystemLog(@PathVariable long id) {
		return systemLogService.deleteById(id) ? ("删除成功") : ("删除失败");
	}

}
